<?

    $n=10;
    //$group=isset($_REQUEST["groupby"])?$_REQUEST["groupby"]:"''";
    //$q=isset($_REQUEST["q"])?$_REQUEST["q"]:null;
    

switch ($group){
    case "Name":
        $groupby="LEFT(`name`,1)";
        break;
    case "Type":
        $groupby="`type`";
        break;
    default :
        $groupby="''";
}
if($type=="trash")
    $nivOrdata=$this->template_model->getTemplates_Trash($groupby,$q);
elseif($type=="public")
    $nivOrdata=$this->template_model->getTemplates_Public($groupby,$q);
elseif($type=="private")
    $nivOrdata=$this->template_model->getTemplates_Private($groupby,$q);
else{
    $nivOrdata=$this->template_model->getTemplates($groupby,$q);
}
?>
<table class="table-data" style="width: 960px;margin-top: 0px">
    <tr>
        <th>No.</th>
        <th>ID</th>
        <th style="min-width: 180px">
            <img style="float: left;  padding-right: 4px;<?=$group!="Name"?"opacity: 0.25;cursor: pointer;":""?>" 
                 src="<?=base_url()?>images/icon/stock_group_cells.png"
                 title="Group by Name"
                 onclick="product_groupby('<?=$type?>','Name');"
                 />
            Name
        </th>
        <th style="min-width: 100px">Status</th>
        <th  style="min-width: 100px">
            <img style="float: left;padding-right: 4px;<?=$group!="Type"?"opacity: 0.25;cursor: pointer;":""?>" 
                 src="<?=base_url()?>images/icon/stock_group_cells.png"
                 title="Group by Type"
                 onclick="product_groupby('<?=$type?>','Type');"
                 />
            Type
        </th>
        <th style="min-width: 100px">
            Insert
        </th>
        <th style="min-width: 100px">
            Update
        </th>
        <th style="min-width: 120px">#</th>
    </tr>
    <?
    if($type!="trash"){
    ?>
    <tr class="id-head-row inew<?=$type?>">
        <td colspan="8">
            <div class="new" style=""
                 onclick="show_item('','inew<?=$type?>');"
                 >
                ++New
            </div>
            
        </td>
    </tr>
    <?
    }
    ?>
    <tr class="id-content-row inew<?=$type?> hidden">
        <td colspan="8">
            <center>đang tải...<br/>
                Nếu trang không tự tải nội dung hãy ấn vào 
                <a class="loadding" href="javascript:show_item('<?=$r["id"]?>','<?=$type?>');">đây</a> để tải lại.<br/>
                Hoặc ấn vào <a href="02_Admin_planners.php?Unit=template_detail&id=<?=$r["id"]?>">đây</a> để tải tại tab khác.
            </center>
        </td>
    </tr>

<?
//organization
$no=0;
$gr="";
if($nivOrdata==null){
    echo "<tr><td colspan='8' style='text-align:center'>No data to display</td></tr>";
}else foreach ($nivOrdata as $r){
    $no++;
    if(strtolower(str_replace(" ", "", $gr))!=strtolower(str_replace(" ", "",$r->group))){
        $gr=$r->group;
        echo "<tr style='background:#D7D7D7'><td colspan='8' ><b>".$group." : ".$r->group."</b></td></tr>";
    }
    if(!$r->status)$status="Private";
    else $status=$r->status;
?>
    <tr class="id-head-row <?=$type?><?=$r->id?> <?=$r->delete?"cred":($r->status!="Private"?"cblue":"")?>">
        <td><?=$no?></td>
        <td><?=$r->id?></td>
        <td><?=$r->name?></td>
        <td>
            <?
            if(!$r->delete){
            ?>
                <span class="showandhide">
                    <span class="hideifhover">
                    <?
                    if($r->status=="Private"){
                        echo "Private";
                    }else{
                        echo "Public";
                    }
                    ?>   
                    </span>
                    <span class="showifhover">
                    <?
                    if($r->status=="Private"){
                        echo "<a href=\"javascript:statusProduct('".$r->id."','Public');\">Private → Public</a>";
                    }else{
                        echo "<a href=\"javascript:statusProduct('".$r->id."','Private');\">Public → Private</a>";
                    }
                    ?>
                    </span>
                </span>
            <?
            }else echo $r->status;
            ?>
        </td>
        <td><?=$r->type?></td>
        <td><?=$r->insert?></td>
        <td><?=$r->update?></td>
        <td style="padding: 0;margin: 0;vertical-align: middle">
            
            
                <?
                if($type=="trash"){
                    ?>
                <div class="icon16 hover50 tooltip" title="Restore"
                     onclick="restoretemplate('<?=$r->id?>');"
                     >
                    
                    <img src="<?=base_url()?>images/icon/gtk_undelete.png">
                </div>
                    <?
                }elseif(!$r->delete){
                ?>
                <span class="action" style="margin-top: 3px">
                <div class="icon16 hover50 tooltip"
                        title="Delete"
                        onclick="deletetemplate('<?=$r->id?>');"
                        >
                    <img src="<?=base_url()?>images/icon/16/edit_delete.png">
                </div>
                <div class="icon16 hover50 tooltip"
                        title="Edit"
                        onclick="show_item('<?=$r->id?>','<?=$type?>');"
                        >
                    <img src="<?=base_url()?>images/icon/16/document_edit.png">
                </div>
                <div class="icon16 hover50 tooltip"
                        title="Album"
                        >
                    <img src="<?=base_url()?>images/icon/16/stock_slide_show.png">
                </div>
                </span>
                <?
                }else{
                ?>
                        
                    <div class="icon16 hover50 tooltip" title="Restore"
                        onclick="restoretemplate('<?=$r->id?>');"
                        >

                        <img src="<?=base_url()?>images/icon/gtk_undelete.png">
                    </div>
                    <span style="line-height: 24px">Deleted at <?=$r->delete;?></span>

                <?
                }
                ?>
            
        </td>
    </tr>
    <tr class="id-content-row <?=$type?><?=$r->id?> hidden">
        <td colspan="8">
            <center>đang tải...<br/>
                Nếu trang không tự tải nội dung hãy ấn vào 
                <a class="loadding" href="javascript:show_item('<?=$r->id?>','<?=$type?>');">đây</a> để tải lại.<br/>
                Hoặc ấn vào <a href="02_Admin_planners.php?Unit=template_detail&id=<?=$r->id?>">đây</a> để tải tại tab khác.
            </center>
        </td>
    </tr>
<?
}
?>
</table>

<div class="clear"></div>
<script>
    $('.tooltip').poshytip({
        className: 'tip-yellowsimple',
        hideTimeout:0,
        alignTo: 'target',
        alignX: 'center',
        allowTipHover: false,
        hideAniDuration:0
    });
</script>